<template>
  <div ref="roundedDonutChart" style="width: 97%; height: 97%"></div>
</template>

<script>
// 引入 ECharts
import * as echarts from 'echarts'
import { getSystemNum } from '@/api/largeScreen'
export default {
  name: 'RoundedDonutChart',
  data() {
    return {
      option: {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center',
          textStyle: {
            color: '#FFFFFF'
          }
        },
        series: [
          {
            name: '总览',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10, // 设置圆角
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: []
          }
        ]
      }
    }
  },
  mounted() {
    this.getSystemNum()
  },
  methods: {
    async getSystemNum() {
      const res = await getSystemNum()
      console.log('right', res)
      this.option.series[0].data = res.map((item, index) => {
        return {
          value: item.count,
          name: item.hostType
        }
      })
      await this.initChart()
    },
    initChart() {
      const chart = echarts.init(this.$refs.roundedDonutChart)
      chart.setOption(this.option)
    }
  }
}
</script>

<style scoped>
/* 你可以在这里添加你的样式 */
</style>
